package com.easy.gao.imageloadertest;

import android.graphics.Rect;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.previewlibrary.GPreviewBuilder;
import com.previewlibrary.ZoomMediaLoader;
import com.previewlibrary.enitity.ThumbViewInfo;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity {

    List<String> imgList = new ArrayList<>();
    @BindView(R.id.rv)
    RecyclerView rv;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        //初始化
        ZoomMediaLoader.getInstance().init(new ImageLoader());
        initData();
    }

    private void initData() {
        for (int i = 0; i < 20; i++) {
            imgList.add("http://pic19.nipic.com/20120308/4970979_102637717125_2.jpg");
        }
        ImageAdapter adapter = new ImageAdapter(this, imgList);
        rv.setLayoutManager(new GridLayoutManager(this, 3));
        rv.setAdapter(adapter);
        adapter.notifyDataSetChanged();


        adapter.setImageListener(new ImageAdapter.ImageListener() {
            @Override
            public void imageLister(int posituon) {
                //定义成成员变量
                ArrayList<ThumbViewInfo> mThbList = new ArrayList<>();
                ThumbViewInfo item;
                for (int i = 0; i < imgList.size(); i++) {
                    Rect bound = new Rect();
                    //图片地址，必须是string的....
                    item = new ThumbViewInfo(imgList.get(i));
                    item.setBounds(bound);
                    mThbList.add(item);
                }

                GPreviewBuilder.from(MainActivity.this)
                        //.to(ImageLoaderActivity.class)//自定义预览窗口，可以不使用
                        .setData(mThbList)
                        .setCurrentIndex(posituon)
                        .setSingleFling(true)
                        .setType(GPreviewBuilder.IndicatorType.Number)
                        .start();//
            }
        });
    }
}
